$(function () {
    //======================
    //======设置查询条件========
    //======================
    //内部公司
    $("#ejzhmx_toolbar [name='gsId']").gsjgtree(1);
    //起始时间
    $("#ejzhmx_toolbar [name='endDate']").datebox();
    //客户加载
    $("[name='khId']").qyjgzcombobox();
    //搜索按钮
    $("#ejzhmx_toolbar [name='searchButton']").click(function () {
        $(grid).datagrid({
            queryParams: {
                endDate: $("#ejzhmx_toolbar [name='endDate']").val(),
                gsId: $("#ejzhmx_toolbar [name='gsId']").val(),
                khId: $("#ejzhmx_toolbar [name='khId']").val()
            }});
    });


//======================
//========统计列表========
//======================
    var yhckcolumns = [
        [
            {field: 'gs', title: '运营商', width: 100, align: 'center'},
            {field: 'kh', title: '代理客户', width: 100, align: 'center'},
            {field: 'ejzhmc', title: '二级账户名称', width: 100, align: 'center'},
            {field: 'zh', title: '二级账户', width: 100, align: 'center'},
            {field: "zhye", title: "账户余额", width: 70, align: 'right', formatter: function (value, row, index) {
                return '<a href="#" id="yhck_zkzh_mx" class="ye-linkbutton" style="color:red" ejzhid="' + row["id"] + '" >' + formatJe2(value, ",", ".") + '</a>';
        }}
        ]
    ];

    var grid = $('#ejzhmx_grid').datagrid({
        url: $.webPath() + '/report/wlz/ejzhmxList',
        toolbar: "#ejzhmx_toolbar",
        rownumbers: true,
        pagination:true,
        singleSelect: true,
        fit: true,
        fitColumns: true,
        queryParams: {
            endDate: $("#ejzhmx_toolbar [name='endDate']").val()
        },
        columns: yhckcolumns,
        onLoadSuccess: function () {
            $(".ye-linkbutton").linkbutton({plain: true}).unbind("click").bind("click", function () {
                $.window({
                    title: '二级账户往来明细',
                    width: 1080,
                    height: 600,
                    cache: false,
                    maximizable: true,
                    url: $.webPath() + '/report/wlz/ejzhmx_detail?ejzhId=' + $(this).attr("ejzhid"),
                    modal: true,
                    buttons: [],
                    onMaximize: function () {
                        $(this).find("#ejzhmx_grid").edatagrid("resize");
                    },
                    onRestore: function () {
                        $(this).find("#ejzhmx_grid").edatagrid("resize");
                    }
                });
            });
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    });
});
